from django.utils.deprecation import MiddlewareMixin


class testmiddleware1(MiddlewareMixin):
    def process_request(self, request):
        """
        请求传来后先执行这个方法
        :param request:
        :return: 不需要返回
        """
        print('---process_request1---')

    def process_view(self, request, view_func, view_args,  view_kwargs):
        """
        视图执行前执行这个方法，这个方法在process_request后执行
        :param request:
        :param view_func:
        :param view_args:
        :param view_kwargs:
        :return: 不需要返回
        """
        print('---process_view1---')

    def process_response(self, request, response):
        """
        视图执行完后， 执行
        :param request:
        :param response:
        :return: 返回response
        """
        print("---process_response1---")
        return response


class testmiddleware2(MiddlewareMixin):
    def process_request(self, request):
        """
        请求传来后先执行这个方法
        :param request:
        :return: 不需要返回
        """
        print('---process_request2---')

    def process_view(self, request, view_func, view_args,  view_kwargs):
        """
        视图执行前执行这个方法，这个方法在process_request后执行
        :param request:
        :param view_func:
        :param view_args:
        :param view_kwargs:
        :return: 不需要返回
        """
        print('---process_view2---')

    def process_response(self, request, response):
        """
        视图执行完后， 执行
        :param request:
        :param response:
        :return: 返回response
        """
        print("---process_response2---")
        return response